package cc.laop.support;

import cc.laop.business.system.ConfigBusiness;
import cc.laop.utils.ApplicationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class ConfigManager {
    private static Configuration config;

    private static ConfigBusiness configService;

    public static String getConfigFromDb(String key) {
        if (configService == null) {
            configService = (ConfigBusiness) ApplicationUtil
                    .getBean(ConfigBusiness.class);
        }
        return configService.getConfig(key);
    }

    public static String getConfigFromFile(String key) {
        if (config == null) {
            try {
                config = new PropertiesConfiguration("config/config.properties");
            } catch (ConfigurationException e) {
                e.printStackTrace();
            }
        }
        return (String) config.getProperty(key);
    }

}
